package edu.nf.waimai.dao.rider.impl;


import edu.nf.util.DBUtils;
import edu.nf.waimai.dao.rider.KnightDAO;
import edu.nf.waimai.model.ridertakeorders.MerchantOrders;
import org.nf.db.util.SqlExecutor;
import org.nf.db.util.result.BeanListHandler;

import java.util.List;

/**
 * @Date 2023-06-20
 * @Author 陈
 */
public class KnightDAOImpl implements KnightDAO {


    @Override
    public List<MerchantOrders> businessOrdersInquire() {

        SqlExecutor executor = new SqlExecutor(DBUtils.getConnection());
        String sql = "SELECT a.address_name AS user_name, a.address_phone AS user_phone, CONCAT(a.province, a.city, a.district, a.detail) AS user_address,\n" +
                "s.shop_name AS shop_name, s.shop_phone AS shop_phone, s.shop_address AS shop_address\n" +
                "FROM orders o INNER JOIN address a ON o.u_id = a.u_id\n" +
                "INNER JOIN shop s ON o.shop_id = s.shop_id\n" +
                "WHERE o.order_status = 1;";
        BeanListHandler<MerchantOrders> handler = new BeanListHandler<>(MerchantOrders.class);
        return executor.executeQuery(sql,handler);
    }

    @Override
    public Integer OrdersRidUpdate(Integer rid,Integer id) {

        SqlExecutor executor = new SqlExecutor(DBUtils.getConnection());
        System.out.println();
        String sql = "update orders set rider_id=? where order_id=?";
        return executor.executeUpdate(sql,rid,id);
    }

    @Override
    public Integer OrdersStaUpdate(Integer sta, Integer rid) {

        SqlExecutor executor = new SqlExecutor(DBUtils.getConnection());
        String sql = "update orders set order_status=? where rider_id=?";
        return executor.executeUpdate(sql,sta,rid);
    }


}